package main

import (
	"context"
	"fmt"
	"net"
	"newtomicroc/rpcconn/pb"
	"newtomicroc/rpcconn/pb/grpc-go"
)

//定义类

type Children struct {
}

func (this *Children) SayHello(ctx context.Context, t *pb.Teacher) (*pb.Teacher, error) {
	t.Name += " is  sleeping"
	return t, nil
}

func main() {
	//1初始一个grpc对象
	grpcServer := grpc.NewServer()
	////2注册服务
	pb.RegisterSayNameServer(grpcServer, new(Children))
	//3 设置监听 绑定ip port
	listener, err := net.Listen("tcp", "127.0.0.1 8800")

	if err != nil {
		fmt.Println("mnet.Listen 失败：", err)
		return
	}
	defer listener.Close()

	//4启动服务
	grpcServer.Serve(listener)
}
